const QQMapWX = require('./qqmap-jssdk.min');
/*
*  坐标转换为地址
*/
function locationTrans(a, fn){ 
  var qqmapsdk = new QQMapWX({
    key: '7NNBZ-NICR6-Y4DSQ-EFS5S-KEWY6-MOBEY' // 必填
  });
  qqmapsdk.reverseGeocoder({
    location: a,
    get_poi: 0,
    success: function (e) {
      var data;
      switch (a.type){
        case 1:
          data = e.result.address_component;
          break;
        case 2:
          data = e.result.formatted_addresses.recommend;
          break;
        default:
          data = { info: e.result.ad_info, address: e.result.address }
          break;
      }
      fn && fn({status:1, data: data})
    },
    fail: function(e){
      fn && fn({ status: 0 })
    }
  })
}
function timeJSON(){
  var arr = [];
  for(var m=2018;m<2021;m++){
    for(var n=1;n<=12;n++){
      var mount = n < 10 ? '0' + n : n;
      var item = m + '-' + mount;
      var day = new Date(m, mount, 0).getDate();
      var days = day < 10 ? '0' + day : day;
      var starTime = new Date(m + '/' + mount + '/01 00:00:00').getTime();
      var endTime = new Date(m + '/' + mount + '/' + days + ' 23:59:59').getTime();
      arr.push({
        sortName: item,
        starTime: starTime,
        endTime: endTime,
      })
    }
  }
  return arr;
}
module.exports = {
	locationTrans: locationTrans,
  timeJSON: timeJSON
}
